package com.ruoyi.leaveManage.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.leaveManage.bo.LeaveUserAddBo;
import com.ruoyi.leaveManage.bo.LeaveUserEditBo;
import com.ruoyi.leaveManage.bo.LeaveUserQueryBo;
import com.ruoyi.leaveManage.service.ILeaveUserService;
import com.ruoyi.leaveManage.vo.LeaveUserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 请假附属Controller
 *
 * @author ruoyi
 * @date 2021-04-26
 */
@Api(value = "请假附属控制器", tags = {"请假附属管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/leave/user")
public class LeaveUserController extends BaseController {
    @Autowired
    private final ILeaveUserService iLeaveUserService;

    /**
     * 查询请假附属列表
     */
    @ApiOperation("查询请假附属列表")
    @PreAuthorize("@ss.hasPermi('leava:user:list')")
    @GetMapping("/list")
    public TableDataInfo<LeaveUserVo> list(LeaveUserQueryBo bo) {
        startPage();
        List<LeaveUserVo> list = iLeaveUserService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出请假附属列表
     */
    @ApiOperation("导出请假附属列表")
    @PreAuthorize("@ss.hasPermi('leava:user:export')")
    @Log(title = "请假附属", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<LeaveUserVo> export(LeaveUserQueryBo bo) {
        List<LeaveUserVo> list = iLeaveUserService.queryList(bo);
        ExcelUtil<LeaveUserVo> util = new ExcelUtil<LeaveUserVo>(LeaveUserVo.class);
        return util.exportExcel(list, "请假附属");
    }

    /**
     * 获取请假附属详细信息
     */
    @ApiOperation("获取请假附属详细信息")
    @PreAuthorize("@ss.hasPermi('leava:user:query')")
    @GetMapping("/{leaveUserId}")
    public AjaxResult<LeaveUserVo> getInfo(@PathVariable("leaveUserId" ) Long leaveUserId) {
        return AjaxResult.success(iLeaveUserService.queryById(leaveUserId));
    }

    /**
     * 新增请假附属
     */
    @ApiOperation("新增请假附属")
    @PreAuthorize("@ss.hasPermi('leava:user:add')")
    @Log(title = "请假附属", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody LeaveUserAddBo bo) {
        return toAjax(iLeaveUserService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改请假附属
     */
    @ApiOperation("修改请假附属")
    @PreAuthorize("@ss.hasPermi('leava:user:edit')")
    @Log(title = "请假附属", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody LeaveUserEditBo bo) {
        return toAjax(iLeaveUserService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除请假附属
     */
    @ApiOperation("删除请假附属")
    @PreAuthorize("@ss.hasPermi('leava:user:remove')")
    @Log(title = "请假附属" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{leaveUserIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] leaveUserIds) {
        return toAjax(iLeaveUserService.deleteWithValidByIds(Arrays.asList(leaveUserIds), true) ? 1 : 0);
    }
}
